<?php

namespace App\Http\Controllers;

use App\utils\AesUtils;
use App\utils\RsaUtils;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

/**
 * 小说控制器
 * author: 姚鸿杰
 * Date: 2019/4/10
 * Time: 21:02
 */
class FictionController extends BaseController
{
    public function test(Request $request)
    {
    }

    public function books(Request $request)
    {
        //todo 创建个基类验证参数
        Log::info($request->toArray());

        if ($code = $this->analysisArgs($request) !== 0) {
            return $this->error($code);
        }

        //无问题后继续执行
        if ($request->input('method', '') === 'getBooks') {
            return $this->getBooks($request);  //获取该用户书架信息
        }


    }

    private function getBooks(Request $request)
    {
        $sign = $request->sign;
        $data = $request->data;
        //数据解密
        $data = $this->decrypt($sign, $data);

        $result = [
            [
                'bookId' => 'ni001',
                'bookName' => '天命赊刀人', 'author' => '困的睡不着', 'cover' => '暂时空着',
                'chapter' => 12, 'charIndex' => 220, 'progress' => '86%',
                'chapterList' => json_encode([
                    ['id' => 1, 'catalog' => '你妹啊'],
                    ['id' => 2, 'catalog' => '好快啊'],
                ])
            ],
            [
                'bookId' => 'ni002',
                'bookName' => '逆天邪神', 'author' => '火星引力', 'cover' => '暂时空着',
                'chapter' => 12, 'charIndex' => 220, 'progress' => '97%',
                'chapterList' => json_encode([
                    ['id' => 1, 'catalog' => '我他妈无语了'],
                    ['id' => 2, 'catalog' => 'UI傻逼'],
                ])
            ],
        ];

        //经过判断若无问题，则返回数据
        return $this->response(200, json_encode($result), '请求成功!');
    }
}
